package test13;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class index {
    public static void main(String[] args) {
        while (true) {
            int x1 = 0;
            boolean xn = true;
            while (xn){
                System.out.println("请输入登录密码，初始密码为123，只有三次试错机会");
                Scanner sc = new Scanner(System.in);
                int password = sc.nextInt();
                if(password==123){
                    System.out.println("登录成功");
                    break;
                }else {
                    x1+=1;
                    int cs = 3-x1;
                    System.out.println("密码错误，请重新输入，还剩"+cs+"次机会");
                    if(x1>=3){
                        System.exit(1);
                    }
                }
            }


            while (true) {
                System.out.println();
                System.out.println("*********************************");
                System.out.println("| 欢迎来到java大杂烩，请根据指示选择功能 |");
                System.out.println("---------------------------------------------------------------");
                System.out.println("| 1：计算美国n年后的人口数量           |  2：输入三个数字求平均数       |");
                System.out.println("| 3：输入年龄判断孩子该上幼儿园什么班    |  4：输入1个数求其形成的金字塔   |");
                System.out.println("| 5：输入一个矩阵，求翻转的牌子在哪里    |  6：一个井字交互小游戏         |");
                System.out.println("| 7：猜拳小游戏                    |  8：退出程序                 |");
                System.out.println("---------------------------------------------------------------");

                Scanner scan = new Scanner(System.in);
                int x = scan.nextInt();
                switch (x) {
                    case 1: {
                        System.out.println("请输入要计算的年数，输入3则是求3年后的");
                        int num = scan.nextInt();
                        CoutPeo count = new CoutPeo(312032486, num);
                        count.coutpeo();
                        System.out.println();
                        break;

                    }
                    case 2: {
                        Averaging aver = new Averaging();
                        aver.avera();
                        System.out.println();
                        break;

                    }
                    case 3: {
                        System.out.println("请输入年龄判断孩子该上幼儿园什么班");
                        int num = scan.nextInt();
                        IsKindergarten isdern1 = new IsKindergarten(num);
                        isdern1.ifGarten();
                        System.out.println();
                        break;
                    }
                    case 4: {
                        System.out.println("请输一个数字来生成金字塔");
                        int num = scan.nextInt();
                        NewPyramid pyramid = new NewPyramid(num);
                        pyramid.createPyramid();
                        System.out.println();
                        break;
                    }
                    case 5: {
                        MatrixNumby numby = new MatrixNumby();
                        System.out.println();
                        break;
                    }
                    case 6: {
                        System.out.println("井字游戏");
                        char[][] board = new char[3][3];
                        TicktacKtoe.displayBoard(board);
                        while (true) {
                            TicktacKtoe.makeAMove(board, 'X');
                            TicktacKtoe.displayBoard(board);
                            if (TicktacKtoe.isWon('X', board)) {
                                System.out.println("玩家 X 获胜");
                                break;
                            } else if (TicktacKtoe.isDraw(board)) {
                                System.out.println("平局");
                                break;
                            }
                            TicktacKtoe.makeAMove(board, 'O');
                            TicktacKtoe.displayBoard(board);
                            if (TicktacKtoe.isWon('O', board)) {
                                System.out.println("玩家 O 获胜");
                                System.out.println();
                                break;
                            } else if (TicktacKtoe.isDraw(board)) {
                                System.out.println("平局");
                                break;
                            }
                        }
                        System.out.println();
                        break;

                    }

                    case 7: {
                        System.out.println("\"石头剪刀布，电脑已就绪！游戏规则如下：和电脑猜拳\n" + " 1【石头】；2【剪刀】；3【布】");
                        int y, p, z, s, f;
                        y = p = z = s = f = 0;

                        Random r = new Random();
                        int a = (int) (Math.random() * 3 + 1);
                        System.out.println("请输入数字猜拳");
                        int b = scan.nextInt();
                        if ((b > 0) && (b < 4)) {
                            System.out.println("你的选择为：" + b);
                            if (a != b) {
                                if ((b - a == -1) || (b - a == 2)) {
                                    System.out.println("不错不错，竟然真的赢了！本次游戏，电脑出" + a + "你出" + b);
                                } else {
                                    System.out.println("还好我技高一筹，你败了！本次游戏，电脑出" + a + "你出" + b);
                                    System.out.println();
                                    break;
                                }

                            } else {
                                System.out.println("你输入的数字不合法，重新输入吧~");
                                System.out.println();
                                break;
                            }
                        }
                    }
                    case 8: {
                        System.out.println("欢迎下次再来~");
                        System.exit(1);
                    }
                    default: {
                        System.out.println("你的输入有误，请重新输入");
                        System.out.println();
                        break;
                    }

                }
            }
        }
    }
}
